#include <bits/stdc++.h>

using namespace std;
#define int long long
const int inf = 0x3f3f3f3f;

void solve()
{
    int a; int k;
    cin >> a >> k;
    for (int i = 1; i < k; i++)
    {
        string s = to_string(a);
        int mi = 10, ma = -1;
        for (auto e : s)
        {
            int x = e - '0';
            mi = min(x, mi);
            ma = max(ma, x);
        }
        if (mi == 0) break;
        a += mi * ma;
    }
    cout << a << endl;
}

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int _ = 1;
    cin >> _;
    while (_--)
    {
        solve();
    }
    return 0;
}